{
 "metadata": {
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  },
  "orig_nbformat": 2,
  "kernelspec": {
   "name": "python385jvsc74a57bd068d7e64a8ef1e11c6d28b945075670502b4996810cedadb5f7222a36b8861f26",
   "display_name": "Python 3.8.5 64-bit ('base': conda)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2,
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#该代码作用是：按照某列分类将一个excel表拆分为多个excel表格\n",
    "import pandas as pd \n",
    "#path_read是读取excel文件路径\n",
    "path_read = r\"E:\\OneDrive\\python\\test.xlsx\"\n",
    "#row_name按照此列进行分类\n",
    "row_name = \"单位\"\n",
    "#path_save是保存路径\n",
    "path_save = r\"E:\\OneDrive\\python\\%s.xlsx\"\n",
    "dfs = pd.read_excel(path_read)\n",
    "\n",
    "positions_list = list(dfs[row_name])\n",
    "for positon in positions_list:\n",
    "    df = dfs[dfs[row_name] == positon]\n",
    "    df.to_excel(path_save%positon,index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ]
}